package com.lxmes.sales.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.lxmes.common.annotation.Log;
import com.lxmes.common.core.controller.BaseController;
import com.lxmes.common.core.domain.AjaxResult;
import com.lxmes.common.enums.BusinessType;
import org.springframework.web.multipart.MultipartFile;
import java.io.IOException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import com.lxmes.sales.domain.ZcBidNotice;
import com.lxmes.sales.service.IZcBidNoticeService;
import com.lxmes.common.utils.poi.ExcelUtil;
import com.lxmes.common.core.page.TableDataInfo;

/**
 * 中标通知单Controller
 *
 * @author lx
 * @date 2023-06-21
 */
@Api(tags = "中标通知单")
@RestController
@RequestMapping("/sales/ZcBidNotice")
public class ZcBidNoticeController extends BaseController
{
    @Autowired
    private IZcBidNoticeService zcBidNoticeService;

    /**
     * 查询中标通知单列表
     */
    @ApiOperation("查询中标通知单列表")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:list')")
    @GetMapping("/list")
    public TableDataInfo list(ZcBidNotice zcBidNotice)
    {
        startPage();
        List<ZcBidNotice> list = zcBidNoticeService.selectZcBidNoticeList(zcBidNotice);
        return getDataTable(list);
    }

    /**
     * 导出中标通知单列表
     */
    @ApiOperation("导出中标通知单列表")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:export')")
    @Log(title = "中标通知单", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZcBidNotice zcBidNotice)
    {
        List<ZcBidNotice> list = zcBidNoticeService.selectZcBidNoticeList(zcBidNotice);
        ExcelUtil<ZcBidNotice> util = new ExcelUtil<ZcBidNotice>(ZcBidNotice.class);
        util.exportExcel(response, list, "中标通知单数据");
    }

    /**
     * 获取中标通知单详细信息
     */
    @ApiOperation("获取中标通知单详细信息")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zcBidNoticeService.selectZcBidNoticeById(id));
    }

    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:edit')")
    @PostMapping(value = "/toOrder/{id}")
    public AjaxResult toOrder(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zcBidNoticeService.toOrder(id));
    }

    /**
     * 新增中标通知单
     */
    @ApiOperation("新增中标通知单")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:add')")
    @Log(title = "中标通知单", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZcBidNotice zcBidNotice)
    {
        return toAjax(zcBidNoticeService.insertZcBidNotice(zcBidNotice));
    }

    /**
     * 修改中标通知单
     */
    @ApiOperation("修改中标通知单")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:edit')")
    @Log(title = "中标通知单", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZcBidNotice zcBidNotice)
    {
        return toAjax(zcBidNoticeService.updateZcBidNotice(zcBidNotice));
    }

    /**
     * 删除中标通知单
     */
    @ApiOperation("删除中标通知单")
    @PreAuthorize("@ss.hasPermi('sales:ZcBidNotice:remove')")
    @Log(title = "中标通知单", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(zcBidNoticeService.deleteZcBidNoticeByIds(ids));
    }
    /**
     * 导入中标通知单
     */
    @Log(title = "中标通知单", businessType = BusinessType.IMPORT)
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file, boolean updateSupport) throws Exception
    {
        ExcelUtil<ZcBidNotice> util = new ExcelUtil<>(ZcBidNotice.class);
        List<ZcBidNotice> zcBidNoticeList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = zcBidNoticeService.imporIteminfo(zcBidNoticeList, updateSupport, operName);
        return AjaxResult.success(message);
    }
    // 下载模板
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response) throws IOException
    {
        ExcelUtil<ZcBidNotice> util = new ExcelUtil<>(ZcBidNotice.class);
        util.importTemplateExcel(response,"中标通知单");
    }

}
